package com.xy.hms.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author xiaye
 * @create 2020-02-24-10:19
 */

//拦截器
public class LoginHandlerIntercepter implements HandlerInterceptor {



    //如果session里取不到loginUser,就返回登录页面，
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {


        Object loginName = request.getSession().getAttribute("loginUser");
        if (loginName==null){

            request.getSession().setAttribute("requireLogin","没有权限，请先登录！");
            request.getRequestDispatcher("/login.html").forward(request,response);
            return false;
        }else {
            return true;
        }

    }


}
